import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// import locale from 'element-ui/lib/locale/lang/zh-CN' // lang i18n
// 导入全局自定义组件
import Components from '@/components/index.js'
// Sass css预处理 参考文档: https://www.sass.hk/guide/
import '@/styles/index.scss' // global css (全局 css)

import App from './App'
import store from './store'
import router from './router'

// 国际化
import i18n from './lang' // Internationalization

// 混入全局方法
import checkPermission from '@/mixin/checkPermission.js'

import '@/icons' // icon
import '@/permission' // permission control

// 方式1-单个注册组件
// import { imgerror } from '@/directive/index.js'
// Vue.directive('imgerror', imgerror)

import * as directives from '@/directive/index.js'
import * as filters from '@/filters/index.js'
// 方式2-通过for in循环遍历对象
// for (const key in directives) {
//   Vue.directive(key, directives[key])
// }
// 方式3-通过Object.keys() 得到对象key的数组,通过循环注册
Object.keys(directives).forEach(key => Vue.directive(key, directives[key]))
Object.keys(filters).forEach(key => Vue.filter(key, filters[key]))

Vue.mixin(checkPermission)
/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
// mock 的模拟数据
// 判断
// if (process.env.NODE_ENV === 'production') {
//   const { mockXHR } = require('../mock')
//   mockXHR()
// }

// set ElementUI lang to EN
Vue.use(ElementUI, {
  i18n: (key, value) => i18n.t(key, value)
})
// 如果想要中文版 element-ui，按如下方式声明
// Vue.use(ElementUI)
// 注册全局自定义组件
Vue.use(Components)

Vue.config.productionTip = false

// 将国际化挂载到Vue实例上
new Vue({
  el: '#app',
  router,
  store,
  i18n,
  render: h => h(App)
})
